<!DOCTYPE html>
<html>
	{include file="public/_header" /}
	<body>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-body ">
							<form class="layui-form" action="">
								<div class="layui-form-item">
									<label class="layui-form-label">字段名称</label>
									<div class="layui-input-inline">
										<input type="text" name="ename" lay-verify="required" autocomplete="off" placeholder="字段名称" class="layui-input">
									</div>
									<div class="layui-form-mid layui-word-aux">字母、数字组成，并且仅能字母开头</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">字段标题</label>
									<div class="layui-input-inline">
										<input type="text" name="cname" lay-verify="required" autocomplete="off" placeholder="字段标题" class="layui-input">
									</div>
									<div class="layui-form-mid layui-word-aux">字段标题</div>
								</div>

								<div class="layui-form-item">
									<label class="layui-form-label">字段类型</label>
									<div class="layui-input-inline">
										<select name="type" lay-verify="required" lay-filter="field_type">
											<option value=""></option>
											{foreach $type as $key=>$vo }
											<option value="{$vo.id}">{$vo.title} | {$vo.name}</option>
											{/foreach}
										</select>
									</div>
									<div class="layui-form-mid layui-word-aux">选取字段类型</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">所在表</label>
									<div class="layui-input-inline">
										<input type="radio" name="table" value="1" title="主表" checked>
										<input type="radio" name="table" value="2" title="附表">
									</div>
									<div class="layui-form-mid layui-word-aux">富文本一般放附表，字符串等放主表</div>
								</div>
								<div class="field_tpl">
									
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">字段提示</label>
									<div class="layui-input-inline">
										<input type="text" name="descript" value="" required lay-verify="required" placeholder="请输入内容" autocomplete="off"
										 class="layui-input">
									</div>
									<div class="layui-form-mid layui-word-aux">字段提示</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">是否必须</label>
									<div class="layui-input-inline">
										<input type="radio" name="validate" value="1" title="是">
										<input type="radio" name="validate" value="2" title="否" checked>
									</div>
									<div class="layui-form-mid layui-word-aux">如果选择是添加信息时必填</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">排序</label>
									<div class="layui-input-inline">
										<input type="number" name="sort" value="100" required lay-verify="required" placeholder="排序" autocomplete="off"
										 class="layui-input">
									</div>
									<div class="layui-form-mid layui-word-aux">排序</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-input-block">
										<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
									</div>
								</div>
							</form>

						</div>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			$(function() {
				layui.use('form', function() {
					var form = layui.form;
					var $ = layui.jquery;
					
					form.on('select(field_type)', function(data){
						var field_type = data.value;
						$.post("{:url('admin/MouldsField/getField')}",{field_type:field_type},function(res){
							$(".field_tpl").html(res);
						})
					}); 
					//监听提交
					form.on('submit(demo1)', function(obj) {
						var lfc = top.layerFrameConfig;
						var iframeBIndex = lfc.iframeB.layer_index;
						var iframeCIndex = lfc.iframeC.layer_index;
						var tableInfo = lfc.iframeC.info;
						obj.field.model_id = lfc.iframeC.id;
						$.post("{:url('admin/MouldsField/fieldadd')}", obj.field, function(res) {
							if (res.status == 1) {
								layer.msg(res.message, {
									icon: 1,
									time: 300
								}, function() {
									parent.layer.close(iframeCIndex);
									tableInfo.reload()
								});
							} else {
								layer.msg(res.message)
							}
						})
						return false;
					});
				});


			})
		</script>

	</body>
</html>
